///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
///////////////////////////////////////////////////////////////////////////////


#include <EAStdC/EAByteCrackers.h>
#include <EAStdCTest/EAStdCTest.h>
#include <EATest/EATest.h>


int TestByteCrackers()
{
	int nErrorCount(0);

	#ifdef _MSC_VER
		#pragma warning (disable: 4310) // Cast truncates constant value
	#endif

	// uint8_t byte manipulators
	uint8_t u8;

	u8 = UINT8_0_FROM_UINT16(0x1100);
	EATEST_VERIFY(u8 == 0x00);
	u8 = UINT8_1_FROM_UINT16(0x1100);
	EATEST_VERIFY(u8 == 0x11);

	u8 = UINT8_0_FROM_UINT32(0x33221100);
	EATEST_VERIFY(u8 == 0x00);
	u8 = UINT8_1_FROM_UINT32(0x33221100);
	EATEST_VERIFY(u8 == 0x11);
	u8 = UINT8_2_FROM_UINT32(0x33221100);
	EATEST_VERIFY(u8 == 0x22);
	u8 = UINT8_3_FROM_UINT32(0x33221100);
	EATEST_VERIFY(u8 == 0x33);

	u8 = UINT8_0_FROM_UINT64(UINT64_C(0x7766554433221100));
	EATEST_VERIFY(u8 == 0x00);
	u8 = UINT8_1_FROM_UINT64(UINT64_C(0x7766554433221100));
	EATEST_VERIFY(u8 == 0x11);
	u8 = UINT8_2_FROM_UINT64(UINT64_C(0x7766554433221100));
	EATEST_VERIFY(u8 == 0x22);
	u8 = UINT8_3_FROM_UINT64(UINT64_C(0x7766554433221100));
	EATEST_VERIFY(u8 == 0x33);
	u8 = UINT8_4_FROM_UINT64(UINT64_C(0x7766554433221100));
	EATEST_VERIFY(u8 == 0x44);
	u8 = UINT8_5_FROM_UINT64(UINT64_C(0x7766554433221100));
	EATEST_VERIFY(u8 == 0x55);
	u8 = UINT8_6_FROM_UINT64(UINT64_C(0x7766554433221100));
	EATEST_VERIFY(u8 == 0x66);
	u8 = UINT8_7_FROM_UINT64(UINT64_C(0x7766554433221100));
	EATEST_VERIFY(u8 == 0x77);


	// uint16_t byte manipulators
	uint16_t u16;

	u16 = UINT16_0_FROM_UINT32(0x33221100);
	EATEST_VERIFY(u16 == 0x1100);
	u16 = UINT16_1_FROM_UINT32(0x33221100);
	EATEST_VERIFY(u16 == 0x3322);

	u16 = UINT16_0_FROM_UINT64(0x7766554433221100LL);
	EATEST_VERIFY(u16 == 0x1100);
	u16 = UINT16_1_FROM_UINT64(0x7766554433221100LL);
	EATEST_VERIFY(u16 == 0x3322);
	u16 = UINT16_2_FROM_UINT64(0x7766554433221100LL);
	EATEST_VERIFY(u16 == 0x5544);
	u16 = UINT16_3_FROM_UINT64(0x7766554433221100LL);
	EATEST_VERIFY(u16 == 0x7766);

	u16 = UINT16_FROM_UINT8(0x11, 0x00);
	EATEST_VERIFY(u16 == 0x1100);


	// uint32_t byte manipulators
	uint32_t u32;

	u32 = UINT32_0_FROM_UINT64(UINT64_C(0x7766554433221100));
	EATEST_VERIFY(u32 == 0x33221100);
	u32 = UINT32_1_FROM_UINT64(UINT64_C(0x7766554433221100));
	EATEST_VERIFY(u32 == 0x77665544);

	u32 = UINT32_FROM_UINT8(0x33, 0x22, 0x11, 0x00);
	EATEST_VERIFY(u32 == 0x33221100);

	u32 = UINT32_FROM_UINT16(0x3322, 0x1100);
	EATEST_VERIFY(u32 == 0x33221100);


	// uint64_t byte manipulators
	uint64_t u64;

	u64 = UINT64_FROM_UINT8(0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00);
	EATEST_VERIFY(u64 == UINT64_C(0x7766554433221100));
	u64 = UINT64_FROM_UINT16(0x7766, 0x5544, 0x3322, 0x1100);
	EATEST_VERIFY(u64 == UINT64_C(0x7766554433221100));
	u64 = UINT64_FROM_UINT32(0x77665544, 0x33221100);
	EATEST_VERIFY(u64 == UINT64_C(0x7766554433221100));

	return nErrorCount;
}





